<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/common.css">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
	<form class="form-horizontal" onsubmit="return false" id="form">
		<fieldset>
			<div class='form-group'>
				<label class='col-md-2 control-label'>客户名称</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='companyName' id='companyName' data-bv-notempty='true' data-bv-notempty-message='客户名称 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>所属行业</label>
				<div class='col-md-10'>
					<select name="industryParaId" id="industryParaId" data-bv-notempty='true' data-bv-notempty-message='所属行业id 不能为空'>
						
					</select>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>注册地</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='registerPlace' id='registerPlace' data-bv-notempty='true' data-bv-notempty-message='注册地 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>客户地址</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='companyAddr' id='companyAddr' >
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>法定代表人</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='legalRepresentative' id='legalRepresentative' >
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>注册资本</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='registeredCapital' id='registeredCapital' >
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>营业期限开始</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='businessTermBegin' id='businessTermBegin'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>营业期限结束</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='businessTermEnd' id='businessTermEnd' >
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>统一社会信用代码</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='creditCode' id='creditCode' data-bv-notempty='true' data-bv-notempty-message='统一社会信用代码 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>商务联系人</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='businessUser' id='businessUser' >
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>商务联系人电话</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='businessUserTel' id='businessUserTel' >
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>归属业务员</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='followUserId' id='followUserId' onclick="openIframeUserList(this)" readonly="readonly" placeholder='点击选择'>
				</div>
			</div>

			<div class="form-actions">
				<div class="row" align="center">
					<div class="col-md-12">
					    <button class="btn btn-primary" onclick="location.href='customerList.html'">返回</button>
						<button class="btn btn-primary" type="submit" onclick="add(1)">
							<i class="fa fa-save"></i> 保存
						</button>
						<button class="btn btn-primary" type="submit" onclick="add(2)">
							<i class="fa fa-save"></i> 保存并提交审核
						</button>
					</div>
				</div>
			</div>

		</fieldset>
	</form>
</div>
	<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
	<script type="text/javascript" src="../../layui/layui.js"></script>
	<script type="text/javascript">
		layui.use(['layer','laydate'], function(){
		    var layer = layui.layer;
		    var laydate = layui.laydate;
		    laydate.render({
		        elem: '#businessTermBegin'
		     });
		     laydate.render({
		        elem: '#businessTermEnd'
		     });
		});
		
		function add(cstatus) {
			$('#form').bootstrapValidator();
			var bootstrapValidator = $("#form").data('bootstrapValidator');
			bootstrapValidator.validate();
		    if(!bootstrapValidator.isValid()){
			   return;
		    }
		    
		    var formdata = $("#form").serializeObject();
		    formdata.status = cstatus;
		    formdata.followUserId = $("#followUserId").attr("followUserId");
			$.ajax({
				type : 'post',
				url : urlRootPrefix + '/customers',
				contentType: "application/json; charset=utf-8",  
				data : JSON.stringify(formdata),
				success : function(data) {
					if(!data.success){
						layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
						$("button[type='submit']").removeAttr("disabled");
						return;
					}
					layer.msg("添加成功", {shift: -1, time: 1000}, function(){
                        location.href = "customerList.html";
                    });
				}
			});
		}
		function getIndustryPara(){
		   	$.ajax({
		           type : 'get',
		           url : urlRootPrefix + '/paraValue/v2/listByParaTypeCode?paraTypeCode=industry',
		           success : function(data) {
			           	if(!data.success){
			           		layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
							return;
						}
			           	var data = data.data;
			           	var typeHtml = "";
			           	for(var i=0;i<data.length;i++){
			           		typeHtml += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
			           	}
			           	$("#industryParaId").append(typeHtml);
		           }
		       });
		}
		getIndustryPara();
		function openIframeUserList(f) {
			var dt = {'ids':$(f).attr("followUserId"),'names':$(f).val()};
			layer.open({
				type : 2,
				title : "选择归属业务员",
				shadeClose : false,
				shade : 0.8,
				maxmin : false, //开启最大化最小化按钮
				area : [ '800px', '650px' ],
				content : urlRootPrefix + "/pages/common/userList.html",
				success: function ( layero,index) {
		        	//找到它的子窗口的body
		            var body = layer.getChildFrame('body', index), iframeWin = window[layero.find('iframe')[0]['name']];  
		          //为子窗口元素赋值
		            body.contents().find("#ids").val(dt.ids);
		            body.contents().find("#names").val(dt.names);
		            //调用子窗口的事件
		            iframeWin.initData();
		            iframeWin.initOrgData();
		        },
				btn : [ '确定', '取消' ],
				yes : function(index, layero) {
					//按钮【按钮一】的回调
					var body = layer.getChildFrame('body', index);
					$("#followUserId").attr("followUserId",body.contents().find("#ids").val());
					$("#followUserId").val(body.contents().find("#names").val());
					layer.close(index);
				}
			});
		}
	</script>
</body>
</html>
